/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/03/10
* File: Mesh.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#pragma once

namespace HY
{
class MeshManager;
class MeshLODLevel;
class Material;

class Mesh
{
public:
	enum
	{
		DrawVertices = 1 << 0,
		DrawNormals = 1 << 1;
	};

public:
	virtual ~Mesh();

	MeshManager* getMeshManager() const;

	uint32 getNumOfLODLevels() const;

	MeshLODLevel *addLODLevel();

	MeshLODLevel *GetLODLevel(uint32 nLODLevel = 0) const;

	uint32 getNumOfMaterials() const;

	Material *addMaterial(Material *pMaterial);

	bool deleteMaterial(uint32 nMaterial);

	Material *getMaterial(uint32 nMaterial = 0) const;

	bool setMaterial(uint32 nMaterial, Material *pMaterial);

	bool deleteMaterial(uint32 mat);

	uint32 getMaterialUsage(uint32 mat) const;

	Material* getMaterial(uint32 mat) const;

	bool setMaterial(uint32 mat, Material* material);

	RenderSystem* getRenderSys() const;

	bool calculateNormals();

	bool calculateTangentSpaceVectors();

	void getBoundingBox(Vector3& vmin, Vector3& vmax);

	void setBoundingBox(const Vector3& vmin, const Vector3& vmax);

	bool calculateBoundingBox(Vector3& vmin, Vector3& vmax);

	bool calculateBoundingSphere(Vector3& pos, float& radius);

	VertexBuffer* getVertexBuffer() const;

protected:
	Mesh(RenderSystem* render_sys, const std::string& name = "");

protected:
	std::string									name_;
	RenderSystem*							render_sys_;
	bool										static_mesh_;
	Vector3										vmin_;
	Vector3										vmax_;
	std::vector<MeshLODLevel*>					lod_levels_;
	std::vector<Material*>						mat_list_;
	VertexBuffer*							vb_;
};

}
